//callback 为0时，unity 传递的函数为null.
mergeInto(LibraryManager.library, {  
    initJsStringToBuffer:function () { 
        window.StringToBuffer = _StringToBuffer;
    },
    // 向数据库中添加数据  
    dbAddData: function(key,data, callback) {  
        window.db_addData(UTF8ToString(key),UTF8ToString(data),callback);
    },
    
    dbAddDataFloat: function(key,data, callback) {  
        window.db_addData(UTF8ToString(key),data,callback);
    },
    
    dbAddDataInt: function(key,data, callback) {  
        window.db_addData(UTF8ToString(key),data,callback);
    },
    //获取数据
    dbGetData: function(key, callback) {  
        //window.db_getData(UTF8ToString(key),callback);
        window.db_getData(UTF8ToString(key),function(result){  
              var newResult = String(result)        
              console.log("result 0 type:", typeof result,result,"tostring",typeof newResult,newResult)
              Module.dynCall_vi(callback,window.StringToBuffer(newResult));               
            });
    },
    
    dbGetDataInt: function(key, callback) {  
        window.db_getData(UTF8ToString(key),function(result){          
            //console.log("result 1 type:", typeof result,result)
            if (typeof result === "number")
            {
               Module.dynCall_vi(callback,result);
            }
            else
            {
              Module.dynCall_vi(callback,0);
            }                  
        });
     },
        
     dbGetDataFloat: function(key, callback) {  
            window.db_getData(UTF8ToString(key),function(result){          
              //console.log("result 2 type:", typeof result,result)
              if (typeof result === "number")
              {
                  Module.dynCall_vf(callback,result);
              }
              else
              {
                Module.dynCall_vf(callback,0);
              }                  
            });
        },
    
    dbDelData: function(key) {  
        window.db_delData(UTF8ToString(key));
    }
});